//太平洋大西洋水流问题
class Solution {
public:
    int m , n;
    int dx[4] = {0,0,-1,1} , dy[4] = {-1,1,0,0};
    void dfs(vector<vector<int>>& heights , int row , int col , vector<vector<bool>>& isLegal)
    {
        isLegal[row][col] = true;
        for(int i = 0 ; i < 4 ; ++i)
        {
            int x = col + dx[i] , y = row + dy[i];
            if(x >= 0 && x < m && y >= 0 && y < n && !isLegal[y][x] && heights[y][x] >= heights[row][col])
            dfs(heights,y,x,isLegal);
        }
    }
    vector<vector<int>> pacificAtlantic(vector<vector<int>>& heights) {
        n = heights.size() , m = heights[0].size();
        vector<vector<int>> ret;
        vector<vector<bool>> pac(n,vector<bool>(m));
        vector<vector<bool>> atl(n,vector<bool>(m));
        for(int i = 0 ; i < n ; ++i) dfs(heights,i,0,pac);
        for(int i = 0 ; i < m ; ++i) dfs(heights,0,i,pac);

        for(int i = 0 ; i < n ; ++i) dfs(heights,i,m-1,atl);
        for(int i = 0 ; i < m ; ++i) dfs(heights,n-1,i,atl);

        for(int i = 0 ; i < n ; ++i)
            for(int j = 0 ; j < m ; ++j) 
                if(pac[i][j] == true && atl[i][j] == true)
                    ret.push_back({i,j});

        return ret;
    }
};

//扫雷游戏
class Solution {
public:
    int n,m;
    int check[51][51];
    vector<vector<char>> updateBoard(vector<vector<char>>& board, vector<int>& click) {
        n = board.size() , m = board[0].size();
        for(int i = 0 ; i < n ; ++i)
        {
            for(int j = 0 ; j < m ; ++j)
            {
                if
            }
        }
    }
};

//衣橱整理
class Solution {
public:
    int m , n , cnt , ret;
    int dx[4] = {0,0,-1,1} , dy[4] = {-1,1,0,0};
    bool vis[101][101];
    bool check(int y , int x)
    {
        int sum = 0;
        while(y)
        {
            sum += (y % 10);
            y /= 10;
        }
        while(x)
        {
            sum += (x % 10);
            x /= 10;
        }
        if(sum <= cnt)
        {
            return true;
        }
        return false;
    }
    void dfs(int row , int col)
    {
        ret++;
        vis[row][col] = true;
        for(int i = 0 ; i < 4 ; ++i)
        {
            int x = col + dx[i] , y = row + dy[i];
            if(x >= 0 && y >= 0 && x < m && y < n && !vis[y][x] && check(x,y))
                dfs(y,x);
        }
    }
    int wardrobeFinishing(int _m, int _n, int _cnt) {
        m = _m , n = _n , cnt = _cnt;
        dfs(0,0);
        return ret;
    }
};